﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DXBase;
using System.Runtime.InteropServices;

namespace DXBase.Structs
{
	// this struct has the same layout as DXBase.color32 and DXGI_FORMAT_B8G8R8A8_UNORM
	[StructLayout(LayoutKind.Sequential)]
	public struct Color4B
	{
		public byte B, G, R, A;

		public Color4B(byte b, byte g, byte r, byte a = 255)
		{
			B = b;
			G = g;
			R = r;
			A = a;
		}

		public static implicit operator Windows.UI.Color(Color4B v) { return Windows.UI.Color.FromArgb(v.A, v.R, v.G, v.B); }
		public static implicit operator Color4B(Windows.UI.Color v) { return new Color4B(v.B, v.G, v.R, v.A); }

		public override string ToString()
		{
			return string.Format("Color({0}, {1}, {2}, {3})", B, G, R, A);
		}
	}

	// DXGI_FORMAT_R32G32B32A32_FLOAT
	[StructLayout(LayoutKind.Sequential)]
	public struct Color4F
	{
		public float R, G, B, A;

		public Color4F(float b, float g, float r, float a = 1)
		{
			B = b;
			G = g;
			R = r;
			A = a;
		}

		public static implicit operator Windows.UI.Color(Color4F v) { return Windows.UI.Color.FromArgb(v.A.Colorb(), v.R.Colorb(), v.G.Colorb(), v.B.Colorb()); }
		public static implicit operator Color4F(Windows.UI.Color v) { return new Color4F(v.B.Colorf(), v.G.Colorf(), v.R.Colorf(), v.A.Colorf()); }

		public static implicit operator Color4F(Color4B v) { return new Color4F(v.B.Colorf(), v.G.Colorf(), v.R.Colorf(), v.A.Colorf()); }
		public static implicit operator Color4B(Color4F v) { return new Color4B(v.A.Colorb(), v.R.Colorb(), v.G.Colorb(), v.B.Colorb()); }

		public override string ToString()
		{
			return string.Format("Color({0}, {1}, {2}, {3})", B, G, R, A);
		}
	}
}
